package cn.xuziao.databasecourse.service;

import cn.xuziao.databasecourse.pojo.ComplexInfo;
import cn.xuziao.databasecourse.pojo.SimpleInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xuziao
 * @date 2021/12/11 20:41
 */
@Service
public class GetModelAndView {

    OssHandle ossHandle;
    Search search;

    @Autowired
    public GetModelAndView(OssHandle ossHandle, Search search) {
        this.ossHandle = ossHandle;
        this.search = search;
    }

    public ModelAndView getIndexModelAndView(){
        ModelAndView modelAndView = new ModelAndView();
        List<SimpleInfo> imgUrl = new ArrayList<>();
        imgUrl.add(search.getSimpleRandomInfoObj(ossHandle.getRandomInfoUrl("imge")));
        imgUrl.add(search.getSimpleRandomInfoObj(ossHandle.getRandomInfoUrl("imge")));
        imgUrl.add(search.getSimpleRandomInfoObj(ossHandle.getRandomInfoUrl("imge")));
        List<ComplexInfo> complexInfo = new ArrayList<>();
        complexInfo.add(search.getComplexRandomInfoObj(ossHandle.getRandomInfoUrl("CNKI/PDF和图像/imge")));
        complexInfo.add(search.getComplexRandomInfoObj(ossHandle.getRandomInfoUrl("CNKI/PDF和图像/imge")));
        complexInfo.add(search.getComplexRandomInfoObj(ossHandle.getRandomInfoUrl("CNKI/PDF和图像/imge")));
        modelAndView.addObject("imgObjs",imgUrl);
        modelAndView.addObject("complexInfoObjs",complexInfo);
        modelAndView.setViewName("index");
        return modelAndView;
    }
}
